package xyz.yuzegod.megawalls.classes.normal.creeper;

import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import xyz.yuzegod.megawalls.classes.Classes;
import xyz.yuzegod.megawalls.classes.Skill;
import xyz.yuzegod.megawalls.game.GamePlayer;
import xyz.yuzegod.megawalls.stats.KitStatsContainer;

import java.util.ArrayList;
import java.util.List;

public class ThirdSkill extends Skill
{
    public ThirdSkill(final Classes classes) {
        super("意志", classes);
    }
    
    @Override
    public int maxedLevel() {
        return 3;
    }
    
    @Override
    public double getAttribute(final int level) {
        switch (level) {
            case 1: {
                return 6.0;
            }
            case 2: {
                return 8.0;
            }
            case 3: {
                return 10.0;
            }
            default: {
                return 6.0;
            }
        }
    }
    
    @Override
    public List<String> getInfo(final int level) {
        final List<String> lore = new ArrayList<String>();
        if (level == 1) {
            lore.add(" §8▪ §7当你的血量低于20时,你获得");
            lore.add("   §7速度II和生命恢复I效果,持续§a" + this.getAttribute(level) + "§7秒。");
            lore.add(" ");
            lore.add("§7冷却时间:§a20秒");
            return lore;
        }
        lore.add(" §8▪ §7当你的血量低于20时,你获得");
        lore.add("   §7速度II和生命恢复I效果,持续§8" + this.getAttribute(level - 1) + " ➜ §a" + this.getAttribute(level) + "§7秒。");
        return lore;
    }
    
    @Override
    public void upgrade(final GamePlayer gamePlayer) {
        final KitStatsContainer kitStats = gamePlayer.getPlayerStats().getKitStats(this.getClasses());
        kitStats.addSkill3Level();
    }
    
    @Override
    public int getPlayerLevel(final GamePlayer gamePlayer) {
        return gamePlayer.getPlayerStats().getKitStats(this.getClasses()).getSkill3Level();
    }
    
    @Override
    public boolean use(final GamePlayer gamePlayer, final KitStatsContainer kitStats) {
        if (Creeper.skill3Cooldown.getOrDefault(gamePlayer, 0) > 0) {
            return false;
        }
        final Player player = gamePlayer.getPlayer();
        if (player.hasPotionEffect(PotionEffectType.SPEED)) {
            player.removePotionEffect(PotionEffectType.SPEED);
        }
        player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, (int)(this.getAttribute(kitStats.getSkill3Level()) * 20.0), 1));
        if (player.hasPotionEffect(PotionEffectType.REGENERATION)) {
            player.removePotionEffect(PotionEffectType.REGENERATION);
        }
        player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, (int)(this.getAttribute(kitStats.getSkill3Level()) * 20.0), 0));
        Creeper.skill3Cooldown.put(gamePlayer, 20);
        return true;
    }
    
    @Override
    public String getSkillTip(final GamePlayer gamePlayer) {
        return this.getClasses().getNameColor() + "§l" + this.getName() + " " + ((Creeper.skill3Cooldown.getOrDefault(gamePlayer, 0) == 0) ? ((gamePlayer.getEnergy() == 100) ? "§a§l✓" : "§c§l✕") : ("§c§l" + Creeper.skill3Cooldown.get(gamePlayer) + "秒"));
    }
}
